package org.example.demo4.controller.freight;

import com.mybatisflex.core.paginate.Page;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.example.demo4.service.SysOperLogService;
import org.example.demo4.model.SysOperLogEntity;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;
import java.util.List;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 操作日志 控制层。
 *
 * @author mybatis-flex-helper automatic generation
 * @since 1.0
 */
@RestController
@RequestMapping("/sysOperLog")
@Tag(name = "操作日志")
public class SysOperLogController {

    @Autowired
    private SysOperLogService sysOperLogService;

    /**
     * 添加 操作日志
     *
     * @param sysOperLog 操作日志
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("/save")
    @Operation(summary = "添加操作日志")
    @Parameters(value = {
            @Parameter(name = "operId", description = "主键id"),

            @Parameter(name = "title", description = "标题"),

            @Parameter(name = "businessType", description = "业务类型"),

            @Parameter(name = "method", description = "方法名全路径"),

            @Parameter(name = "requestMethod", description = "方法名"),

            @Parameter(name = "operatorType", description = "操作类型"),

            @Parameter(name = "operName", description = "操作人"),

            @Parameter(name = "deptName", description = "操作部门"),

            @Parameter(name = "operUrl", description = "接口路径"),

            @Parameter(name = "operIp", description = "ip地址"),

            @Parameter(name = "operLocation", description = "内外网"),

            @Parameter(name = "operParam", description = "请求参数"),

            @Parameter(name = "jsonResult", description = "请求返回"),

            @Parameter(name = "status", description = "状态"),

            @Parameter(name = "errorMsg", description = ""),

            @Parameter(name = "operTime", description = "")
    })
    public boolean save(@RequestBody SysOperLogEntity sysOperLog) {
        return sysOperLogService.save(sysOperLog);
    }


    /**
     * 根据主键删除操作日志
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("/remove/{id}")
    @Operation(summary = "根据主键删除操作日志")
    @Parameters(value = {
            @Parameter(name = "operId", description = "主键id", required = true)
    })
    public boolean remove(@PathVariable Serializable id) {
        return sysOperLogService.removeById(id);
    }


    /**
     * 根据主键更新操作日志
     *
     * @param sysOperLog 操作日志
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PutMapping("/update")
    @Operation(summary = "根据主键更新操作日志")
    @Parameters(value = {
            @Parameter(name = "operId", description = "主键id", required = true),

            @Parameter(name = "title", description = "标题"),

            @Parameter(name = "businessType", description = "业务类型"),

            @Parameter(name = "method", description = "方法名全路径"),

            @Parameter(name = "requestMethod", description = "方法名"),

            @Parameter(name = "operatorType", description = "操作类型"),

            @Parameter(name = "operName", description = "操作人"),

            @Parameter(name = "deptName", description = "操作部门"),

            @Parameter(name = "operUrl", description = "接口路径"),

            @Parameter(name = "operIp", description = "ip地址"),

            @Parameter(name = "operLocation", description = "内外网"),

            @Parameter(name = "operParam", description = "请求参数"),

            @Parameter(name = "jsonResult", description = "请求返回"),

            @Parameter(name = "status", description = "状态"),

            @Parameter(name = "errorMsg", description = ""),

            @Parameter(name = "operTime", description = "")
    })
    public boolean update(@RequestBody SysOperLogEntity sysOperLog) {
        return sysOperLogService.updateById(sysOperLog);
    }


    /**
     * 查询所有操作日志
     *
     * @return 所有数据
     */
    @GetMapping("/list")
    @Operation(summary = "查询所有操作日志")
    public List<SysOperLogEntity> list() {
        return sysOperLogService.list();
    }


    /**
     * 根据操作日志主键获取详细信息。
     *
     * @param id sysOperLog主键
     * @return 操作日志详情
     */
    @GetMapping("/getInfo/{id}")
    @Operation(summary = "根据操作日志主键获取详细信息")
    @Parameters(value = {
            @Parameter(name = "operId", description = "主键id", required = true)
    })
    public SysOperLogEntity getInfo(@PathVariable Serializable id) {
        return sysOperLogService.getById(id);
    }


    /**
     * 分页查询操作日志
     *
     * @param page 分页对象
     * @return 分页对象
     */
    @GetMapping("/page")
    @Operation(summary = "分页查询操作日志")
    @Parameters(value = {
            @Parameter(name = "pageNumber", description = "页码", required = true),
            @Parameter(name = "pageSize", description = "每页大小", required = true)
    })
    public Page<SysOperLogEntity> page(Page<SysOperLogEntity> page) {
        return sysOperLogService.page(page);
    }
}